//
// Created by xzy.xiao on 2022/6/10.
//

#include "LogEventFilter.h"
#include <iostream>
#include <QEvent>

/**
 * 过滤器
 * @param watched 被处理的组件
 * @param event 组件接收到的事件
 * @return true：拦截该事件    false：放行该事件
 */
bool LogEventFilter::eventFilter(QObject *watched, QEvent *event) {
    std::cout << "Component:" << watched->objectName().toStdString() << "  Event:" << getEventStr(event) << std::endl;
    return QObject::eventFilter(watched, event);
}

std::string LogEventFilter::getEventStr(QEvent *event) {
    switch (event->type()) {
        case QEvent::Type::None:
            return "invalid event";
        case QEvent::Type::Timer:
            return "timer event";
        case QEvent::Type::MouseButtonPress:
            return "mouse button pressed";
        case QEvent::Type::MouseButtonRelease:
            return "mouse button released";
        case QEvent::Type::MouseButtonDblClick:
            return "mouse button double click";
        case QEvent::Type::MouseMove:
            return "mouse move";
        case QEvent::Type::KeyPress:
            return "key pressed";
        case QEvent::Type::KeyRelease:
            return "key released";
        case QEvent::Type::FocusIn:
            return "keyboard focus received";
        case QEvent::Type::FocusOut:
            return "keyboard focus lost";
        case QEvent::Type::FocusAboutToChange:
            return "keyboard focus is about to be lost";
        case QEvent::Type::Enter:
            return "mouse enters widget";
        case QEvent::Type::Leave:
            return "mouse leaves widget";
        case QEvent::Type::Paint:
            return "paint widget";
        case QEvent::Type::Move:
            return "move widget";
        case QEvent::Type::Resize:
            return "resize widget";
        case QEvent::Type::Create:
            return "after widget creation";
        case QEvent::Type::Destroy:
            return "during widget destruction";
        case QEvent::Type::Show:
            return "widget is shown";
        case QEvent::Type::Hide:
            return "widget is hidden";
        case QEvent::Type::Close:
            return "request to close widget";
        case QEvent::Type::Quit:
            return "request to quit application";
        case QEvent::Type::ParentChange:
            return "widget has been reparented";
        case QEvent::Type::ParentAboutToChange:
            return "sent just before the parent change is done";
        case QEvent::Type::ThreadChange:
            return "object has changed threads";
        case QEvent::Type::WindowActivate:
            return "window was activated";
        case QEvent::Type::WindowDeactivate:
            return "window was deactivated";
        case QEvent::Type::ShowToParent:
            return "widget is shown to parent";
        case QEvent::Type::HideToParent:
            return "widget is hidden to parent";
        case QEvent::Type::Wheel:
            return "wheel event";
        case QEvent::Type::WindowTitleChange:
            return "window title changed";
        case QEvent::Type::WindowIconChange:
            return "icon changed";
        case QEvent::Type::ApplicationWindowIconChange:
            return "application icon changed";
        case QEvent::Type::ApplicationFontChange:
            return "application font changed";
        case QEvent::Type::ApplicationLayoutDirectionChange:
            return "application layout direction changed";
        case QEvent::Type::ApplicationPaletteChange:
            return "application palette changed";
        case QEvent::Type::PaletteChange:
            return "widget palette changed";
        case QEvent::Type::Clipboard:
            return "internal clipboard event";
        case QEvent::Type::Speech:
            return "reserved for speech input";
        case QEvent::Type::MetaCall:
            return "meta call event";
        case QEvent::Type::SockAct:
            return "socket activation";
        case QEvent::Type::WinEventAct:
            return "win event activation";
        case QEvent::Type::DeferredDelete:
            return "deferred delete event";
        case QEvent::Type::DragEnter:
            return "drag moves into widget";
        case QEvent::Type::DragMove:
            return "drag moves in widget";
        case QEvent::Type::DragLeave:
            return "drag leaves or is cancelled";
        case QEvent::Type::Drop:
            return "actual drop";
        case QEvent::Type::DragResponse:
            return "drag accepted/rejected";
        case QEvent::Type::ChildAdded:
            return "new child widget";
        case QEvent::Type::ChildPolished:
            return "polished child widget";
        case QEvent::Type::ChildRemoved:
            return "deleted child widget";
        case QEvent::Type::ShowWindowRequest:
            return "widget's window should be mapped";
        case QEvent::Type::PolishRequest:
            return "widget should be polished";
        case QEvent::Type::Polish:
            return "widget is polished";
        case QEvent::Type::LayoutRequest:
            return "widget should be relayouted";
        case QEvent::Type::UpdateRequest:
            return "widget should be repainted";
        case QEvent::Type::UpdateLater:
            return "request update() later";
        case QEvent::Type::EmbeddingControl:
            return "ActiveX embedding";
        case QEvent::Type::ActivateControl:
            return "ActiveX activation";
        case QEvent::Type::DeactivateControl:
            return "ActiveX deactivation";
        case QEvent::Type::ContextMenu:
            return "context popup menu";
        case QEvent::Type::InputMethod:
            return "input method";
        case QEvent::Type::TabletMove:
            return "Wacom tablet event";
        case QEvent::Type::LocaleChange:
            return "the system locale changed";
        case QEvent::Type::LanguageChange:
            return "the application language changed";
        case QEvent::Type::LayoutDirectionChange:
            return "the layout direction changed";
        case QEvent::Type::Style:
            return "internal style event";
        case QEvent::Type::TabletPress:
            return "tablet press";
        case QEvent::Type::TabletRelease:
            return "tablet release";
        case QEvent::Type::OkRequest:
            return "CE (Ok) button pressed";
        case QEvent::Type::HelpRequest:
            return "CE (?)  button pressed";
        case QEvent::Type::IconDrag:
            return "proxy icon dragged";
        case QEvent::Type::FontChange:
            return "font has changed";
        case QEvent::Type::EnabledChange:
            return "enabled state has changed";
        case QEvent::Type::ActivationChange:
            return "window activation has changed";
        case QEvent::Type::StyleChange:
            return "style has changed";
        case QEvent::Type::IconTextChange:
            return "icon text has changed";
        case QEvent::Type::ModifiedChange:
            return "modified state has changed";
        case QEvent::Type::MouseTrackingChange:
            return "mouse tracking state has changed";
        case QEvent::Type::WindowBlocked:
            return "window is about to be blocked modally";
        case QEvent::Type::WindowUnblocked:
            return "windows modal blocking has ended";
        case QEvent::Type::WindowStateChange:
            return "WindowStateChange";
        case QEvent::Type::ReadOnlyChange:
            return "readonly state has changed";
        case QEvent::Type::ToolTip:
            return "ToolTip";
        case QEvent::Type::WhatsThis:
            return "WhatsThis";
        case QEvent::Type::StatusTip:
            return "StatusTip";
        case QEvent::Type::ActionChanged:
            return "ActionChanged";
        case QEvent::Type::ActionAdded:
            return "ActionAdded";
        case QEvent::Type::ActionRemoved:
            return "ActionRemoved";
        case QEvent::Type::FileOpen:
            return "file open request";
        case QEvent::Type::Shortcut:
            return "shortcut triggered";
        case QEvent::Type::ShortcutOverride:
            return "shortcut override request";
        case QEvent::Type::WhatsThisClicked:
            return "WhatsThisClicked";
        case QEvent::Type::ToolBarChange:
            return "toolbar visibility toggled";
        case QEvent::Type::ApplicationActivate:
            return "ApplicationActivate";
        case QEvent::Type::ApplicationDeactivate:
            return "ApplicationDeactivate";
        case QEvent::Type::QueryWhatsThis:
            return "query what's this widget help";
        case QEvent::Type::EnterWhatsThisMode:
            return "EnterWhatsThisMode";
        case QEvent::Type::LeaveWhatsThisMode:
            return "LeaveWhatsThisMode";
        case QEvent::Type::ZOrderChange:
            return "child widget has had its z-order changed";
        case QEvent::Type::HoverEnter:
            return "mouse cursor enters a hover widget";
        case QEvent::Type::HoverLeave:
            return "mouse cursor leaves a hover widget";
        case QEvent::Type::HoverMove:
            return "mouse cursor move inside a hover widget";
        default:
            return "";
    }
}
